/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package linkeddata.arida.ufc.br.servlet;

import java.io.File;
import java.io.IOException;
import java.util.LinkedHashSet;
import java.util.Set;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import linkeddata.arida.ufc.br.manager.impl.BuildsSparqlQuery;
import linkeddata.arida.ufc.br.util.OWLUtils;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;

/**
 *
 * @author jeovane
 */
public class ObtainsValuesMenuServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        String domainOntology = request.getParameter("domainOntology");
        String jsonTextQuery = request.getParameter("mapKey");
        String jsonTextOptional = request.getParameter("mapVal");
        String activeUnion = "";
        String query = "";
        File file = new File("/home/jeovane/Dropbox/NetBeansProjects/JBOS/JBOS/web/prefixes.xml");
        
        OWLUtils utils = new OWLUtils(domainOntology);
        utils.ontologyLoaded();
        BuildsSparqlQuery bsq = new BuildsSparqlQuery(utils.getOntology(), utils.getPm(), utils.getReasoner(), file);

        Set<String> setFilter = new LinkedHashSet<String>();

        try {
            bsq.buildsSelect(jsonTextQuery, activeUnion);
            query = bsq.buildsWhere(jsonTextQuery, jsonTextOptional, setFilter);
        } catch (OWLOntologyCreationException ex) {
            System.out.println("Erro: " + ex.getMessage());
        }

        response.setContentType("text/plain");
        response.setCharacterEncoding("UTF-8");
        response.getWriter().write(query);
    }
    
}
